Skip to content

feat: B622 — Detect logging/printing of sensitive information#1386

Closed
ghost wants to merge 2 commits into
mainfrom
unknown repository
Closed

feat: B622 — Detect logging/printing of sensitive information#1386
ghost wants to merge 2 commits into
mainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 12, 2026

Summary

Implements #1371 — adds a new Bandit plugin that detects when sensitive information is passed to logging or print calls.

What it detects

Flags calls to logging.*, print(), and pprint.* where arguments contain variable names associated with secrets:

  • password, passwd, pwd, passphrase
  • secret, api_key, apikey, api_secret, client_secret
  • token, auth_token, bearer
  • private_key, access_key, secret_key, signing_key
  • credential, database_url, db_password, encryption_key

What it does NOT flag (false positive avoidance)

  • username, user_name, total_count, elapsed, etc.
  • Generic print/logging with non-sensitive variables
  • Format strings without sensitive arguments

Test results

10 true positives detected
0 false positives on safe code

Example

# ❌ Flagged
logging.debug("Password: %s", password)
print(f"Token: {auth_token}")
logging.info("Key: %s" % private_key)

# ✅ Not flagged
logging.debug("User logged in: %s", username)
print("Hello world")
logging.info("Request completed in %s seconds", elapsed)

Files changed

  • bandit/plugins/logging_sensitive_info.py — New plugin (155 lines)
  • examples/sensitive_logging.py — Test cases
  • setup.cfg — Plugin registration

Closes #1371

Implements #1371 — flags when sensitive variable names (password, token,
api_key, private_key, etc.) are passed to logging calls or print().

Detection covers:
- logging.debug/info/warning/error calls
- print() and pprint.pprint()
- f-string interpolation with sensitive vars
- keyword arguments with sensitive names

10 test cases, 0 false positives on safe code (username, count, etc).

CWE: CLEARTEXT_TRANSMISSION (CWE-319)
@ghost ghost requested review from ericwb, lukehinds and sigmavirus24 as code owners April 12, 2026 15:02
@ghost ghost closed this by deleting the head repository Apr 13, 2026
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag logging/printing of likely sensitive information

0 participants